Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clean] Respect permissions of sanitised files #3292

Conversation

pmoravec
Copy link
Contributor

When copying files we applied a substitution in, we must replace just original file content (shutil.copyfile) and not also its stat data (shutil.copy).

Resolves: #3292


Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines

  • Is the commit message split over multiple lines and hard-wrapped at 72 characters?
  • Is the subject and message clear and concise?
  • Does the subject start with [plugin_name] if submitting a plugin patch or a [section_name] if part of the core sosreport code?
  • Does the commit contain a Signed-off-by: First Lastname [email protected]?
  • Are any related Issues or existing PRs properly referenced via a Closes (Issue) or Resolved (PR) line?

When copying files we applied a substitution in, we must replace just
original file content (shutil.copyfile) and not also its stat data
(shutil.copy).

Resolves: sosreport#3292

Signed-off-by: Pavel Moravec <[email protected]>
@packit-as-a-service
Copy link

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo yum install -y dnf-plugins-core on RHEL 8
  • sudo dnf install -y dnf-plugins-core on Fedora
  • dnf copr enable packit/sosreport-sos-3292
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

@pmoravec
Copy link
Contributor Author

Forgot a trivial reproducer:

  1. Ensure /etc/hosts has system's FQDN, e.g. add there:

echo $(ip a | grep -v "127.0.0.1/8" | grep -m1 "inet " | cut -d/ -f1 | awk '{ print $2 }') $(hostname -f) $(hostname -s) >> /etc/hosts

  1. Run:
# sos report --clean -o networking --batch --build
..
Your sosreport build tree has been generated in:
     /var/tmp/sosreport-host4-8675309-2023-06-28-cxezxnp
  1. Compare permissions:
# ll /etc/hosts /var/tmp/sosreport-host4-8675309-2023-06-28-cxezxnp/etc/hosts
-rw-r--r--. 1 root root 1134 Jun 12 08:37 /etc/hosts
-rw-------. 1 root root  798 Jun 28 16:49 /var/tmp/sosreport-host4-8675309-2023-06-28-cxezxnp/etc/hosts
#

See the missing go+r flags.

@TurboTurtle
Copy link
Member

Should we add a test to ensure the permissions match on a given file (like /etc/hosts or /etc/hostname)?

@pmoravec
Copy link
Contributor Author

I was thinking about it, but thought "would that test be usefull / why we would cause here a regression?" - but if also you have raised the concern about adding a test, I will add one (once I find proper assert method, probably comparing stat objects..?).

Add a test that cleaner keeps permissions of a sanitised file

Relevant to: sosreport#3292

Signed-off-by: Pavel Moravec <[email protected]>
@pmoravec
Copy link
Contributor Author

pmoravec commented Jun 29, 2023

I added a test case, but it does pass even without the codechange; whenever sos is run within avocado, the collected (sanitised) file has proper permissions. I dont understand why..

Please decide about the test case in either way, I am off for a few weeks.

Copy link
Member

@TurboTurtle TurboTurtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test looks right, but the behavior from avocado is odd. I'm of the mind to accept this now, and investigate the test suite separately as manual inspection shows this working as intended.

@TurboTurtle TurboTurtle merged commit fc1489a into sosreport:main Jun 30, 2023
30 checks passed
TurboTurtle pushed a commit that referenced this pull request Jun 30, 2023
When copying files we applied a substitution in, we must replace just
original file content (shutil.copyfile) and not also its stat data
(shutil.copy).

Resolves: #3292

Signed-off-by: Pavel Moravec <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants